from ..data_structures.base_structures import *
from ..enums.pp_enum import AttributeType


class ShpQuantifierComponents(Enum):
    """量化shp的组件们"""

    QuantifyBasecellsWithWater = 'quantify_basecells_with_water'
    QuantifyBasecellsWithVegetation = 'quantify_basecells_with_vegetation'
    QuantifyBasecellsWithBuilding = 'quantify_basecells_with_building'
    QuantifyBasecellsWithSoil = 'quantify_basecells_with_soil'
    QuantifyBasecellsWithRoad = 'quantify_basecells_with_road'
    QuantifyBasecellsWithGeology = 'quantify_basecells_with_geology'

    @staticmethod
    def quantify_basecells_with_water(fclass:str, row, cell:BaseCell):
        """量化水体"""
        if fclass == 'water':
            # 水体类型
            type = row.get('type', AttributeType.UNKNOWN.value)
            # 水深属性
            depth = row.get('depth', 127.0)  # 默认值给到127.0
            # 地质类型
            bottom_geology = row.get('bottom', '未知') # 默认值给到'未知'
            # 流速
            flow_speed = row.get('flow_speed', 0.0) # 默认值给到0.0
            # 水体宽度
            width = row.get('width', 0.0) # 默认值给到0.0
            # 岸边陡峭程度
            bank_steepness = row.get('steepness', '0.0')  # 默认值给到0.0  
            # 创建水体属性对象
            water = Water(1)
            water.add_sub_attribute(Water.Type(type))  # 添加水体类型子属性
            water.add_sub_attribute(Water.Depth(depth))  # 添加水深子属性
            water.add_sub_attribute(Water.BottomGeology(bottom_geology))  # 添加底质子属性
            water.add_sub_attribute(Water.FlowSpeed(flow_speed))
            water.add_sub_attribute(Water.Width(width))  # 添加水体宽度子属性
            water.add_sub_attribute(Water.BankSteepness(bank_steepness))  # 添加岸边陡峭程度子属性
            # 将水体属性对象添加到cell的属性数组中
            cell.attributes.append(water)

    @staticmethod
    def quantify_basecells_with_vegetation(fclass:str, row, cell:BaseCell):
        """量化植被"""
        if fclass == 'vegetation':
            # 植被类型
            type = row.get('type', AttributeType.UNKNOWN.value)
            # 植被密度
            density = row.get('density', 1.0) # 默认值给到1.0
            # 平均植被高度
            average_height = row.get('average_height', 1.0) # 默认值给到1.0
            # 平均植株胸径
            average_crown_diameter = row.get('diameter', 1.0) # 默认值给到1.0
            # 林冠层郁闭度
            canopy_closure = row.get('closure', 1.0) # 默认值给到1.0
            # 创建植被属性对象
            vegetation = Vegetation(1)
            vegetation.add_sub_attribute(Vegetation.Type(type))
            vegetation.add_sub_attribute(Vegetation.Density(density))  # 添加植被密度子属性
            vegetation.add_sub_attribute(Vegetation.AverageHeight(average_height))
            vegetation.add_sub_attribute(Vegetation.AveragePlantDiameter(average_crown_diameter))
            vegetation.add_sub_attribute(Vegetation.CanopyClosure(canopy_closure))
            # 将植被属性对象添加到cell的属性数组中
            cell.attributes.append(vegetation)

    @staticmethod
    def quantify_basecells_with_building(fclass:str, row, cell:BaseCell):
        """量化建筑物"""
        if fclass == 'building': # 建筑物
            # 建筑物类型
            type = row.get('type', AttributeType.UNKNOWN.value)
            # 建筑物硬度
            hardness = row.get('hardness', 0.0)
            # 建筑物可破坏性
            destructibility = row.get('destruct', 0.0)
            # 创建建筑物属性对象
            building = Building(1)
            building.add_sub_attribute(Building.Type(type))  # 添加建筑物类型子属性
            building.add_sub_attribute(Building.Hardness(hardness))  # 添加建筑物硬度子属性
            building.add_sub_attribute(Building.Destructibility(destructibility))
            # 将建筑物属性对象添加到cell的属性数组中
            cell.attributes.append(building)

    @staticmethod
    def quantify_basecells_with_soil(fclass:str, row, cell:BaseCell):
        """量化土壤"""
        if fclass == 'soil':
            # 土壤类型
            type = row.get('type', AttributeType.UNKNOWN.value)
            # 土壤硬度
            hardness = row.get('hardness', 0.0)
            # 土壤承载力
            bearing_capacity = row.get('bearing', 0.0)
            # 表层土厚度
            surface_soil_thickness = row.get('thickness', 0.0)
            # 创建土壤属性对象
            soil = Soil(1)
            soil.add_sub_attribute(Soil.Type(type))
            soil.add_sub_attribute(Soil.Hardness(hardness))
            soil.add_sub_attribute(Soil.BearingCapacity(bearing_capacity))
            soil.add_sub_attribute(Soil.SurfaceSoilThickness(surface_soil_thickness))
            # 将土壤属性对象添加到cell的属性数组中
            cell.attributes.append(soil)

    @staticmethod
    def quantify_basecells_with_geology(fclass: str, row, cell: BaseCell):
        """量化地质"""
        if fclass == 'geology':
            # 地质类型
            type = row.get('type', AttributeType.UNKNOWN.value)
            # 岩石类型·
            rocktype = row.get('rocktype', AttributeType.UNKNOWN.value)
            # 褶皱
            wrinkle = row.get('wrinkle', 0.0)
            # 断层
            fault = row.get('fault', 0.0)
            # 创建地质属性对象
            geology = Geology(2)
            geology.add_sub_attribute(Geology.Type(type))
            geology.add_sub_attribute(Geology.Lithology(rocktype))
            geology.add_sub_attribute(Geology.Wrinkle(wrinkle))
            geology.add_sub_attribute(Geology.Fault(fault))
            # 将地质属性对象添加到cell的属性数组中
            cell.attributes.append(geology)


    @staticmethod
    def quantify_basecells_with_road(fclass:str, row, cell:BaseCell):
        """量化道路"""
        if fclass == 'road':
            cell.road_type = RoadType.NORMALWAY.value